﻿using System;
using System.Collections.Generic;
using System.Text;

namespace CO2FixCalibration
{
    class DataSet
    {
        List<int> years = new List<int>();
        List<double> values = new List<double>();

        string label;


        public double Sum
        {
            get
            {
                double sum = 0;
                foreach (double v in values) sum += v;
                return sum;
            }
        
        }

        public double Avg
        {
            get
            {
                return Sum / (float)values.Count;
            }
        }

        public double Sigma
        {
            get
            {
                double ctr = 0;
                foreach (double v in values) ctr += Math.Pow((v - Avg), 2);
                return ctr/((float)values.Count - 1);
            }
        }

        public string Label
        {
            get
            {
                return label;
            }
        }
        public double FirstValue
        {
            get
            {
                return values[0];
            }
        }
        public float MaxValue
        {
            get
            {
                float max = float.MinValue;
                foreach(float v in values)
                {
                    if (v > max) max = v;
                }
                return max;
            }
        }
        public DataSet(string label)
        {
            this.label = label;
        }
        public string GetValueAtTimeAsString(int time)
        {
            double d = GetValueAtTime(time);
            if (d == double.MinValue) return "";
            else return Math.Round(d,2).ToString();
        }
        public double GetValueAtTime(int time)
        {
            for (int m = 0; m < NrOfPoints; m++)
            {
                if (Time[m] == time)
                {
                    return values[m];
                }
            }
            return double.MinValue;
        }

        public void IncreaseTime(int AddYrs)
        {
            for (int y = 0; y < years.Count; y++)
            {
                years[y] += AddYrs;
            }
        }

        public List<int> Time 
        {
            get
            {
                return years;
            }
        }
         
        public int FirstTime
        {
            get
            {
                return years[0];
            }
        }
        public int LastTime
        {
            get
            {
                return years[years.Count - 1];
            }
        }
        public double NrOfPoints
        {
            get
            {
                return values.Count;
            }
        }
        public DataSet(DataSet d)
        {
            this.label = d.label;
            foreach (int y in d.years) years.Add(y);
            foreach (double v in d.values) values.Add(v);

        }
        
        public void Add(int year, double value)
        {
            years.Add(year);
            values.Add(value);
        }
    }
}
